package edu.xjtu.jih.control;

import org.apache.ibatis.session.SqlSession;
import edu.xjtu.jih.common.Utils;

import java.util.List;

public class ConService {
    public ConService() {

    }

    public List<user> getUserList() {
        SqlSession sess = Utils.openSession();

        try{
            UserDao dao = sess.getMapper(UserDao.class);
            List<user> userList = dao.finduserList();
            sess.commit();

            return userList;

        }catch(Exception e){
            sess.rollback();
            throw new RuntimeException("查询用户信息失败！",e);
        }finally {
            sess.close();
        }

    }


    public List<item> getItemList() {
        SqlSession sess = Utils.openSession();

        try{

            UserDao dao = sess.getMapper(UserDao.class);
            List<item> itemList = dao.getItemList();
            sess.commit();
            return itemList;
        }catch (Exception e){
            sess.rollback();
            throw  new RuntimeException("查询商品信息失败！",e);
        }finally {
            sess.close();
        }
    }

    public void deleteUser(user itemd) {
        SqlSession sess = Utils.openSession();
        try{
            UserDao dao = sess.getMapper(UserDao.class);
            dao.deleteU(itemd);
            sess.commit();
        }catch (Exception e){
            sess.rollback();
            throw  new RuntimeException("删除用户信息失败！",e);
        }finally {
            sess.close();
        }
    }

    public void deleteItem(item itemd) {
        SqlSession sess = Utils.openSession();
        try{
            UserDao dao = sess.getMapper(UserDao.class);
            dao.deleteI(itemd);
            sess.commit();
        }catch (Exception e){
            sess.rollback();
            throw  new RuntimeException("删除商品信息失败！",e);
        }finally {
            sess.close();
        }
    }
}
